var app = getApp();
const pathUrl = app.globalData.pathUrl;
Page({
    data: {
        pathUrl: pathUrl,
        openId: '',
        id:'',
        height: '', //屏幕高度
        latitude:'',
        longitude:'',
        posName:'',
        posNo:'',
        posConcract:'',
        posMobile:'',
        posAddr:''
    },
    onLoad: function (options) {
        var openId = wx.getStorageSync('openId');
        this.setData({
            openId: openId
        });
        this.getSystemInfo();
        this.gotGps();
        this.getShopInfo();
    },
    // 获取设备高度
    getSystemInfo: function() {
        var that = this;
        wx.getSystemInfo({
            success: function (e) {
                console.log(e);
                that.setData({
                    height: (e.screenHeight)-240
                })
            }
        })
    },
    // 获取经纬度
    gotGps: function () {
        var that = this;
        wx.getLocation({
            type: 'wgs84',
            success(res) {
                that.setData({
                    latitude: res.latitude,
                    longitude: res.longitude
                });
            }
        });
    },
    // 获取商户基本信息
    getShopInfo:function() {
        var that = this;
        wx.request({
            url: pathUrl + '/rest/posDetailController/getbyopenid/' + that.data.openId,
            method:"GET",
            success: function (res){
                if(res.data.ok){
                    that.setData({
                        id: res.data.data.id,
                        posName: res.data.data.posName,
                        posNo:res.data.data.posNo,
                        posConcract: res.data.data.posConcract,
                        posMobile: res.data.data.posMobile,
                        posAddr: res.data.data.posAddr
                    })
                }
            }
        })
    },
    creatPosxjtast:function(e){
        var that = this;
        console.log(e);
        wx.showModal({
            title: '商户巡检系统',
            content: '您确定提交' + e.currentTarget.dataset.posxjtype,
            confirmColor: '#007aff',
            cancelColor: '#007aff',
            confirmText: '确认',
            cancelText: '取消',
            success: function (res) {
                if (res.confirm) {
                    wx.request({
                        url: pathUrl + '/rest/posXjtaskController/',
                        method: 'POST',
                        data: {
                            id: that.data.id,
                            posXjType: e.currentTarget.dataset.posxjtype
                        },
                        success: function (res) {
                            if (res.data.ok) {
                                wx.showToast({
                                    title: '提交成功',
                                    duration: 500,
                                    mask: true,
                                })
                            }
                        }
                    })
                }
            }
        })

    },

    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        this.posXjtaskController();
        wx.stopPullDownRefresh();
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})